const path = require("path"),
      webpack = require("webpack"),
      HtmlWebpackPlugin = require("html-webpack-plugin"),
      ExtractTextPlugin = require('extract-text-webpack-plugin');

      module.exports = {
        context : path.resolve(__dirname,"./static/"),
        devtool:"source-map",
        entry : {
            app : "./js"
        },
        output : {
            path : path.resolve(__dirname,"./assets"),
            publicPath : "./",
            filename : "js/[name].js"
        },
        resolve: {
            extensions: ['.js', '.css','jpg'], //后缀名自动补全
        },
        module : {
            rules : [
                {
                    test : /\.js|jsx$/,
                    use : {
                        loader : "babel-loader"
                    },
                    exclude : "/node_modules"
                },
                {
                    test : /\.css$/,
                    use: ExtractTextPlugin.extract({
                        fallback: "style-loader",
                        use: [{
                            loader: "css-loader",
                            options: {
                                name : "css/[name].[exe]",
                                publicPath : "css/"
                            }
                        }, {
                            loader: "postcss-loader"
                        }]
                    })
                },
                {
                    test: /\.jpg$/,
                    loader: "url-loader",
                    options:{
                        limit: 10000,
                        mimetype:"image/png",
                        name: 'img/[name].[ext]',
                        // publicPath:"../"
                    }
                },
                {
                    test:/\.png$/,
                    loader:"file-loader",
                    options:{
                        limit:10000,
                        mimetype:"image/png",
                        name:"img/[name].[ext]"
                    }
                },
                {
                    test: /\.art$/,
                    use: [ 'art-template-loader' ]
                }
            ]
        },
        plugins :[
            new webpack.BannerPlugin('版权所有，翻版必究'),
            new webpack.optimize.CommonsChunkPlugin({
                name : "common",
                fliename:"common.js",
                minChunks :2
            }),// 默认会把所有入口节点的公共代码提取出来,生成一个common.js
            new ExtractTextPlugin({
                filename:"css/[name].css",
                allChunks: true
            }),
            new webpack.NoEmitOnErrorsPlugin(),//解决阻塞,编译完成再报错
            new HtmlWebpackPlugin({
                title:'图片放大镜效果',
                template: 'html-withimg-loader!'+path.resolve('./static/html/','index.html'), // 源模板文件
                filename: './index.html', // 输出文件【注意：这里的根路径是module.exports.output.path】
                showErrors: true,
                inject: 'body',
                chunks: "all",
                minify: false,
                hash: true
            }),
            new webpack.optimize.OccurrenceOrderPlugin(),//【排序输出】
            new webpack.optimize.UglifyJsPlugin({//【压缩】
                compress: {
                    warnings: false
                }
            })
        ]
      }